﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Protocols;
using System.Collections;
using com.huawei.esdk.tp.professional.eSDKTPProfessionalConfCtrl;
using com.huawei.esdk.tp.professional.DataType;
using com.huawei.esdk.tp.professional.Utils;

namespace com.huawei.esdk.tp.professional.local
{
    public partial class ConferenceCtrlServiceEx
    {
        private static string url = com.huawei.esdk.tp.professional.Utils.UtilsSettings.URL + com.huawei.esdk.tp.professional.Utils.UtilsSettings.tpProfessionalConfCtrl;
        private static TPProfessionalConfCtrService confCtrl = new TPProfessionalConfCtrService(url);

        private static ConferenceCtrlServiceEx instance = null;
        protected ConferenceCtrlServiceEx()
        {

        }
        public static ConferenceCtrlServiceEx Instance()
        {
            if (null == instance)
            {
                instance = new ConferenceCtrlServiceEx();
            }
            return instance;
        }

        //设置指定会场的视频源
        public int setVideoSourceEx(string confId, string siteUri, string videoSourceUri, int? isLock)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                bool isLockSpecified = false;
                if(isLock != null)
                    isLockSpecified = true;
                int resultCode = confCtrl.setVideoSourceEx(confId, siteUri, videoSourceUri, isLock, isLockSpecified);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        public int setAudioSwitchEx(string confId, int? switchGate, int isSwitch)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                bool switchGateSpecified = false;
                if (switchGate != null)
                    switchGateSpecified = true;
                
                int resultCode = confCtrl.setAudioSwitchEx(confId, switchGate, switchGateSpecified, isSwitch);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        public int setBroadcastSiteEx(string confId, string siteUri, int isBroadcast)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode;

                resultCode = confCtrl.setBroadcastSiteEx(confId, siteUri, isBroadcast);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int setBroadcastContinuousPresenceEx(string confId, int isBroadcast)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.setBroadcastContinuousPresenceEx(confId, isBroadcast);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int setSitesMuteEx(string confId, List<string> siteUris, int isMute)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode;
                string[] sites = null;
                if (null != siteUris)
                {
                    sites = siteUris.ToArray<string>();
                }


                resultCode = confCtrl.setSitesMuteEx(confId, sites, isMute);
                return resultCode;

            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int setSitesQuietEx(string confId, List<string> siteUris, int isQuiet)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode;
                string[] sites = null;
                if (null != siteUris)
                {
                    sites = siteUris.ToArray<string>();
                }


                resultCode = confCtrl.setSitesQuietEx(confId, sites, isQuiet);
                return resultCode;

            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int setContinuousPresenceEx(string confId, string target, int presenceMode, List<string> subPics)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                string[] pics = null;
                int resultCode;
                if (null != subPics)
                {
                    pics = subPics.ToArray<string>();
                }


                resultCode = confCtrl.setContinuousPresenceEx(confId, target, presenceMode, pics);
                return resultCode;

            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        /// <summary>
        ///  指定会场发言
        /// </summary>
        /// <param name="confid">会议ID</param>
        /// <param name="siteUri">会场Uri</param>
        /// <returns>返回码：0表示成功；其他为失败</returns>
        public int setFloorEx(string confid,string siteUri)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.setFloorEx(confid, siteUri);
                return resultCode;
            }
            catch(SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e) ;
            }
            
        }

        /// <summary>
        /// 设置会场音量
        /// </summary>
        /// <param name="confid">会议ID</param>
        /// <param name="siteVolume">音量</param>
        /// <returns>返回码：0表示成功；其他为失败</returns>
        public int setConfSiteVolumeEx(string confid,SiteVolumeEx[] siteVolume)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.setConfSiteVolumeEx(confid, siteVolume);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        /// <summary>
        /// 打开会议中会场的视频
        /// </summary>
        /// <param name="confid">会议ID</param>
        /// <param name="siteUri">打开视频会场的URI列表</param>
        /// <returns>返回码：0表示成功；其他为失败</returns>
        public int displayConfSiteLocalVideoEx(string confid, string[] siteUri)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.displayConfSiteLocalVideoEx(confid, siteUri);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        /// <summary>
        /// 打开会议中会场的视频
        /// </summary>
        /// <param name="confid">会议ID</param>
        /// <param name="siteUri">打开视频会场的URI列表</param>
        /// <returns>返回码：0表示成功；其他为失败</returns>
        public int HideConfSiteLocalVideoEx(string confid, string[] siteUri)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.hideConfSiteLocalVideoEx(confid, siteUri);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        // 2015年1月15日 新增接口

        //解锁的演示者令牌
        public int unlockPresentationEx(string confId)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.unlockPresentationEx(confId);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        //锁定的演示者令牌
        public int lockPresentationEx(string confId, string siteUri)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.lockPresentationEx(confId, siteUri);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        // 2015年1月22日 新增接口

        //申请主席
        public int requestConfChairEx(string confId, string chairmanUri)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.requestConfChairEx(confId, chairmanUri);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        //释放主席
        public int releaseConfChairEx(string confId)
        {
            try
            {
                confCtrl.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = confCtrl.releaseConfChairEx(confId);
                return resultCode;

            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }
    }
}
